`<template>
	<view class="register-container">
		<view class="header">
			<text class="back" @tap="goBack">返回</text>
			<text class="title">注册账号</text>
		</view>

		<view class="form-box">
			<view class="input-group">
				<text class="iconfont icon-phone"></text>
				<input type="number" v-model="form.phone" placeholder="请输入手机号" maxlength="11" />
			</view>

			<view class="input-group verify-group">
				<text class="iconfont icon-safe"></text>
				<input type="number" v-model="form.code" placeholder="请输入验证码" maxlength="6" />
				<text class="verify-btn" :class="{ disabled: counting }" @tap="sendCode">
					{{counting ? countDown + 's' : '获取验证码'}}
				</text>
			</view>

			<view class="input-group">
				<text class="iconfont icon-lock"></text>
				<input type="password" v-model="form.password" placeholder="请设置密码" />
			</view>

			<view class="input-group">
				<text class="iconfont icon-lock"></text>
				<input type="password" v-model="form.confirmPassword" placeholder="请确认密码" />
			</view>

			<button class="register-btn" @tap="handleRegister">注册</button>

			<view class="agreement">
				<checkbox :checked="agreed" @tap="toggleAgreement" color="#07c160" />
				<text class="agreement-text">我已阅读并同意</text>
				<text class="link" @tap="showAgreement">《用户协议》</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form: {
					phone: '',

					password: '',
					confirmPassword: ''
				},
				agreed: false,
				counting: false,
				countDown: 60
			}
		},
		methods: {
			goBack() {
				uni.navigateBack()
			},
			sendCode() {
				if (this.counting) return
				if (!this.form.phone) {
					uni.showToast({
						title: '请输入手机号',
						icon: 'none'
					})
					return
				}
				if (!/^1[3-9]\d{9}$/.test(this.form.phone)) {
					uni.showToast({
						title: '手机号格式不正确',
						icon: 'none'
					})
					return
				}

				// TODO: 调用发送验证码接口
				this.counting = true
				this.countDown = 60
				const timer = setInterval(() => {
					this.countDown--
					if (this.countDown <= 0) {
						clearInterval(timer)
						this.counting = false
					}
				}, 1000)
			},
			handleRegister() {
				if (!this.form.phone || !this.form.code || !this.form.password || !this.form.confirmPassword) {
					uni.showToast({
						title: '请填写完整信息',
						icon: 'none'
					})
					return
				}
				if (!this.agreed) {
					uni.showToast({
						title: '请阅读并同意用户协议',
						icon: 'none'
					})
					return
				}
				if (this.form.password !== this.form.confirmPassword) {
					uni.showToast({
						title: '两次密码输入不一致',
						icon: 'none'
					})
					return
				}

				// TODO: 实现注册逻辑
				uni.showLoading({
					title: '注册中...'
				})
				setTimeout(() => {
					uni.hideLoading()
					uni.showToast({
						title: '注册成功',
						icon: 'success'
					})
					setTimeout(() => {
						uni.navigateBack()
					}, 1500)
				}, 1500)
			},
			toggleAgreement() {
				this.agreed = !this.agreed
			},
			showAgreement() {
				uni.navigateTo({
					url: '/pages/agreement/agreement'
				})
			}
		}
	}
</script>

<style lang="scss">
	.register-container {
		min-height: 100vh;
		background: #fff;

		.header {
			position: relative;
			height: 88rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			border-bottom: 1rpx solid #eee;

			.back {
				position: absolute;
				left: 30rpx;
				font-size: 28rpx;
				color: #666;
			}

			.title {
				font-size: 32rpx;
				font-weight: bold;
				color: #333;
			}
		}

		.form-box {
			padding: 40rpx;

			.input-group {
				display: flex;
				align-items: center;
				border-bottom: 1rpx solid #eee;
				padding: 20rpx 0;
				margin-bottom: 30rpx;

				.iconfont {
					font-size: 40rpx;
					color: #666;
					margin-right: 20rpx;
				}

				input {
					flex: 1;
					font-size: 28rpx;
				}
			}

			.verify-group {
				.verify-btn {
					font-size: 26rpx;
					color: #07c160;
					padding: 10rpx 20rpx;
					border: 1rpx solid #07c160;
					border-radius: 30rpx;

					&.disabled {
						color: #999;
						border-color: #999;
					}
				}
			}

			.register-btn {
				background: #07c160;
				color: #fff;
				border-radius: 40rpx;
				margin: 40rpx 0;
				font-size: 32rpx;

				&:active {
					opacity: 0.8;
				}
			}

			.agreement {
				display: flex;
				align-items: center;
				justify-content: center;
				font-size: 26rpx;
				color: #666;

				.agreement-text {
					margin: 0 10rpx;
				}

				.link {
					color: #07c160;
				}
			}
		}
	}
</style>`